home *** CD-ROM | disk | FTP | other *** search
- Private derivation can be thought of as a syntactic variant of containment (has-a). Ex: it is NOT true that a privately derived is-a-kind-of-a Base:
-
- With private derivation:
- class Car : private Engine {/*...*/}; //a Car is NOT a-kind-of Engine
- Similarly:
- class Car { Engine e; /*...*/ }; //normal containment
-
- There are several similarities between these two forms of containment:
- * in both cases there is exactly one Engine subobject contained in a Car
- * in neither case can clients (outsiders) convert a Car* to an Engine*
-
- There are also several distinctions:
- * the second form is needed if you want to contain several subobjects
- * the first form can introduce unnecessary multiple inheritance
- * the first form allows members of Car to convert a Car* to an Engine*
- * the first form allows access to the 'protected' members of the base class
-
- Private inheritance is almost always used for the last item: to gain access into the 'protected:' members of the base class.